#include <stdio.h>
#include <strings.h>

//.bss
int bss_1;
int bss_2;
char bss_3;
char bss_4;
char bss_5[16];
char bss_6;

// .data 
int data_3 = 2;
int data_4 = 2;
int data_5 = 2;
int data_6 = 2;
int data_7 = 1;
const char *data_8 = "hhhhhhh\n"; 
char data_9[8] = "hhhhhhh\n";
int data_10 = 1;

//rodata
const int rodata_1 =1; 


int main(void)
{


	printf("############### Stack ###################\n");
	int *stack_1;
	int *stack_2;

	const char *stack_3 = "hhhhhhh\n";
	char  * const stack_4 = stack_3;

	int *stack_5; 
	stack_5 = &data_5;

	int *stack_6; 
	stack_6= &bss_1;

	char stack_7[16] = "ab";
	char *stack_ptr_1;
	char stack_8 = '8';
	int *stack_9;

	printf("Stack +4 : %08p\n", &stack_1);
	printf("Stack +4 : %08p\n", &stack_2+1);
	printf("Stack +4 : %08p\n", &stack_2);
	printf("Stack +4 : %08p\n", &stack_3);
	printf("Stack +4 : %08p\n", &stack_4);
	printf("Stack +4 : %08p\n", &stack_5);
	printf("Stack +4 : %08p\n", &stack_6);
	printf("Stack +1 : %08p\n", stack_7+1);
	printf("Stack +16 : %08p\n", stack_7);
	printf("Stack +4 : %08p\n", &stack_ptr_1);
	printf("Stack +1 : %08p\n", &stack_8);
	printf("#########################################\n");

	printf("######### ShARED LIB  #############\n");
	stack_9 = (int *)malloc(1024*1024);
	printf("Share lib : %08p\n", stack_9);
	printf("#########################################\n");

	printf("######### FREE SPACE(HEAP)  #############\n");
	stack_ptr_1 = (char *)malloc(2);
	strcpy(stack_ptr_1,"d");

	stack_3 = (char *)malloc(100);
	strcpy(stack_3,"djf\n");

	stack_2 = (int *)malloc(4);
	stack_1 = (int *)malloc(32);

	printf("heap +32 : %08p\n", stack_1);
	printf("heap +4 : %08p\n", stack_2+1);
	printf("heap +4 : %08p\n", stack_2);
	printf("heap +100 : %08p\n", stack_3);
	printf("heap +2 : %08p\n", stack_ptr_1);
	printf("#########################################\n");

	printf("############### BSS Section #############\n");

	bss_3 = 'a';
	printf(".bss section bss_1 value : %d\n", bss_1);
	printf(".bss section bss_3 value : %c\n", bss_3);
	printf(".bss section bss_2 value : %d\n", bss_2);

	printf(".bss section +1 : %08p\n", &bss_4);
	printf(".bss section +4 : %08p %08p\n", &bss_1,stack_6);
	printf(".bss section +16 : %08p\n", &bss_5);
	printf(".bss section +1 : %08p\n", &bss_3);
	printf(".bss section +1 : %08p\n", &bss_6);
	printf(".bss section +4 : %08p\n", &bss_2);
	printf("#########################################\n");

	printf("############### DATA Section ############\n");
	printf(".data section +4 : %08p\n", &data_10);
	printf(".data section +1 : %08p\n", data_9+1);
	printf(".data section +8 : %08p\n", &data_9);
	printf(".data section +8 : %08p\n", data_9);
	printf(".data section +4 : %08p\n", &data_8+1);
	printf(".data section +4 : %08p\n", &data_8);
	printf(".data section +4 : %08p\n", &data_7);
	printf(".date section +4 : %08p\n", &data_6);
	printf(".date section +4 : %08p %08p\n", &data_5,stack_5);
	printf(".date section +4 : %08p\n", &data_4);
	printf(".date section +4 : %08p\n", &data_3);
	printf("#########################################\n");

	printf("############### RODATA Section ##########\n");
	printf(".rodata section +4: %08p\n", &rodata_1);
	printf(".rodata section: %08p\n", data_8+1);
	printf(".rodata section: %08p %08p\n", data_8,stack_4);
	printf("#########################################\n");
	
	return 0;
}

